import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import '../../model/danger2.dart';

import '../../spaces/recordspace/record_list.dart';

import 'danger_info.dart';

class Danger2DetailPage extends StatefulWidget {
  @override
  Danger2DetailPage(this.danger2);
  final Danger2 danger2;

  @override
  createState() => new Danger2DetailPageState();
}

class Danger2DetailPageState extends State<Danger2DetailPage> {
  late Danger2 s1;
  bool ifLoad = false;

//  定义底部导航列表
  final List<BottomNavigationBarItem> bottomTabs = [
    new BottomNavigationBarItem(icon: new Icon(Icons.info), label: ('基础信息')),
    new BottomNavigationBarItem(icon: new Icon(Icons.image), label: ('工作记录')),
  ];

  Widget getBody(int i) {
    if (i == 0) return Danger2InfoPage(s1, () => {});
    if (i == 1) return RecordListPage(s1.Guid, false);

    return new Container();
  }

  int currentIndex = 0; //当前索引
  late Widget currentPage; //当前页面

  @override
  void initState() {
    super.initState();
    s1 = widget.danger2;
    ifLoad = true;
    currentPage = getBody(0);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        // title: bottomTabs[currentIndex].title,
        title: Text("隐患排查登记单"),
        // leading: Icon(Icons.menu),
      ),
      bottomNavigationBar: new BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: currentIndex,
          items: bottomTabs,
          fixedColor: Colors.blue,
          onTap: (index) {
            setState(() {
              currentIndex = index;
              currentPage = getBody(currentIndex);
            });
          }),
      body: ifLoad
          ? currentPage
          : Center(
              child: SpinKitCircle(
              color: Colors.blue,
            )),
    );
  }
}
